home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 182_01 / rbsb.c < prev    next >
Text File  |  1990-07-30  |  4KB  |  183 lines

  1. /* -rev 07-02-85
  2.  * mode function and most of the rest of the system dependent
  3.  * stuff for rb.c and sb.c   This file is #included so the includer
  4.  * can set parameters such as HOWMANY.
  5.  */
  6.  
  7. #ifdef USG
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <termio.h>
  11. #include <sys/ioctl.h>
  12. #define OS "USG"
  13. #endif
  14.  
  15. #ifdef V7
  16. #include <sys/types.h>
  17. #include <sys/stat.h>
  18. #include <sgtty.h>
  19. #define OS "V7"
  20. #endif
  21.  
  22. #ifndef OS
  23. #include <termio.h>
  24. #include <sys/ioctl.h>
  25. #include <stat.h>
  26. #define REGULUS
  27. #define ONEREAD
  28. #define OS "REGULUS"
  29. #define void int
  30. #define time_t long
  31. #endif
  32.  
  33.  
  34. #ifdef ICANON
  35. struct termio oldtty, tty;
  36. #else
  37. struct sgttyb oldtty, tty;
  38. struct tchars oldtch, tch;
  39. #endif
  40.  
  41. int iofd = 0;        /* File descriptor for ioctls & reads */
  42.  
  43. /*
  44.  * mode(n)
  45.  *  2: set a cbreak, XON/XOFF control mode if using Pro-YAM's -g option
  46.  *  1: save old tty stat, set raw mode 
  47.  *  0: restore original tty mode
  48.  */
  49. mode(n)
  50. {
  51.     static did0 = FALSE;
  52.  
  53.     switch(n) {
  54. #ifdef USG
  55.     case 2:    /* Cbreak mode used by sb when -g detected */
  56.         if(!did0)
  57.             (void) ioctl(iofd, TCGETA, &oldtty);
  58.         tty = oldtty;
  59.  
  60.         tty.c_iflag = BRKINT|IXON;
  61.  
  62.         tty.c_oflag = 0;    /* Transparent output */
  63.  
  64.         tty.c_cflag &= ~PARENB;    /* Disable parity */
  65.         tty.c_cflag |= CS8;    /* Set character size = 8 */
  66.  
  67.         tty.c_lflag = ISIG;
  68.         tty.c_cc[VINTR] = 030;    /* Interrupt on CANCEL */
  69.  
  70.         (void) ioctl(iofd, TCSETA, &tty);
  71.         did0 = TRUE;
  72.         return OK;
  73.     case 1:
  74.         if(!did0)
  75.             (void) ioctl(iofd, TCGETA, &oldtty);
  76.         tty = oldtty;
  77.  
  78.         tty.c_iflag = IGNBRK;
  79.  
  80.          /* No echo, crlf mapping, INTR, QUIT, delays, no erase/kill */
  81.         tty.c_lflag &= ~(ECHO | ICANON | ISIG);
  82.         tty.c_lflag |= XCLUDE;
  83.  
  84.         tty.c_oflag = 0;    /* Transparent output */
  85.  
  86.         tty.c_cflag &= ~PARENB;    /* Leave baud rate alone, disable parity */
  87.         tty.c_cflag |= CS8;    /* Set character size = 8 */
  88.         tty.c_cc[VMIN] = HOWMANY; /* Satisfy reads when this many chars in */
  89.         tty.c_cc[VTIME] = 1;    /* ... or in this many tenths of seconds */
  90.         (void) ioctl(iofd, TCSETA, &tty);
  91.         did0 = TRUE;
  92.         return OK;
  93. #endif
  94. #ifdef V7
  95.     case 2:
  96.         if(!did0) {
  97.             ioctl(iofd, TIOCEXCL, 0);
  98.             ioctl(iofd, TIOCGETP, &oldtty);
  99.             ioctl(iofd, TIOCGETC, &oldtch);
  100.         }
  101.         tty = oldtty;
  102.         tch = oldtch;
  103.         tch.t_intrc = 030;
  104.         tty.sg_flags |= CBREAK;
  105.         tty.sg_flags &= ~ECHO;
  106.         ioctl(iofd, TIOCSETP, &tty);
  107.         ioctl(iofd, TIOCSETC, &tch);
  108.         did0 = TRUE;
  109.         return OK;
  110.     case 1:
  111.         if(!did0) {
  112.             ioctl(iofd, TIOCEXCL, 0);
  113.             ioctl(iofd, TIOCGETP, &oldtty);
  114.             ioctl(iofd, TIOCGETC, &oldtch);
  115.         }
  116.         tty = oldtty;
  117.         tty.sg_flags |= RAW;
  118.         tty.sg_flags &= ~ECHO;
  119.         ioctl(iofd, TIOCSETP, &tty);
  120.         did0 = TRUE;
  121.         return OK;
  122. #endif
  123. #ifdef REGULUS
  124.     case 2:
  125.         return ERROR;
  126.     case 1:
  127.         if(!did0) {
  128.             ioctl(iofd, TCGETA, &oldtty);
  129.         }
  130.         tty = oldtty;
  131.  
  132.         tty.c_lflag = 0;
  133.         tty.c_iflag = IGNBRK;
  134.         tty.c_oflag = 0;    /* Transparent output */
  135.  
  136.         tty.c_cflag &= ~PARENB;    /* Leave baud rate alone, disable parity */
  137.         tty.c_cflag |= CS8;    /* Set character size = 8 */
  138.         tty.c_cc[VMIN] = HOWMANY; /* Satisfy reads when this many chars in */
  139.         tty.c_cc[VTIME] = 1;    /* ... or in this many tenths of seconds */
  140.         ioctl(iofd, TCSETA, &tty);
  141.         did0 = TRUE;
  142.         return OK;
  143. #endif
  144. #ifdef REGULUS10
  145.         if(!did0) {
  146.             ioctl(iofd, TIOCGETP, &oldtty);
  147.         }
  148.         /* Sorry, No structure assignment in Regulus  C */
  149.         movmem( (char *)&oldtty, (char *)&tty, sizeof(tty));
  150.         tty.sg_flags |= (EIGHTBIT|RAW);
  151.         tty.sg_flags &= ~ECHO;
  152.         tty.sg_ledit &= ~LEDIT;
  153.         ioctl(iofd, TIOCSETP, &tty);
  154.         did0 = TRUE;
  155.         return OK;
  156. #endif
  157.     case 0:
  158.         if(!did0)
  159.             return ERROR;
  160. #ifdef USG
  161.         (void) ioctl(iofd, TCSBRK, 1);    /* Wait for output to drain */
  162.         (void) ioctl(iofd, TCFLSH, 1);    /* Flush input queue */
  163.         (void) ioctl(iofd, TCSETAW, &oldtty);    /* Restore original modes */
  164.         (void) ioctl(iofd, TCXONC,1);    /* Restart output */
  165. #endif
  166. #ifdef V7
  167.         ioctl(iofd, TIOCSETP, &oldtty);
  168.         ioctl(iofd, TIOCSETC, &oldtch);
  169.         ioctl(iofd, TIOCNXCL, 0);
  170. #endif
  171. #ifdef REGULUS
  172.         ioctl(iofd, TCSETAW, &oldtty);    /* Restore original modes */
  173. #endif
  174. #ifdef REGULUS10
  175.         ioctl(iofd, TIOCSETP, &oldtty);
  176. #endif
  177.         return OK;
  178.     default:
  179.         return ERROR;
  180.     }
  181. }
  182.  
  183.